/*****************************************************************************\
 *                            RESTRICTED RIGHTS LEGEND
 *
 *      Use, duplication, or disclosure by the Government is subject to
 *      restrictions as set forth in subparagraph (c) (1) (ii) of the Rights in
 *      Technical Data and Computer Software Clause at DFARS 252.227-7013.
 *
 *      The Board of Trustees of the University of Illinois
 *      109 Coble Hall
 *      801 South Wright Street
 *      Champaign, IL 61820-6242
 *
 *      File: AccessRule.cs
 *
 *      Authors: Erich Heine, David Rodgers, Denis Kholine, Derek Dagit,
 *      William H. Sanders, Klara Nahrstedt, Rakesh Bobba, Tim Yardley
 *      Creation Date: 2012
 *
 *      Copyright (c) 2012 William H. Sanders, Klara Nahrstedt, Erich Heine,
 *      Rakesh Bobba, Tim Yardley,
 *      and The Board of Trustees of the University of Illinois
 *      All rights reserved.
 * 
 *      No further use, distribution, or disclosure beyond internal development 
 *      project participants (Grid Protection Alliance and University of Illinois)
 *      is allowed.
 *
 \*****************************************************************************/

﻿using System;

namespace SIEGate.Acl
{
    public enum AccessRuleType
    {
        Allow,
    }

    public enum Verb
    {
        NoPermission = 0,
        SubscribePermission = 1
    }


    public abstract class AccessRule : IEquatable<AccessRule>   
    {
        #region Properties

        public Subject subject
        {
            get;
            set;
        }

        public Verb verb
        {
            get;
            set;
        }

        public Resource resource
        {
            get;
            set;
        }

        public abstract AccessRuleType type
        {
            get;
        }

        #endregion


        public AccessRule(Subject subject, Verb verb, Resource resource) 
        {
            this.subject = subject;
            this.verb = verb;
            this.resource = resource;
        }

        #region IEquatable<AccessRule> Members

        public bool Equals(AccessRule other)
        {
            return this.type == other.type
                && this.verb == other.verb
                && this.resource.Equal(other.resource)
                && this.subject.GetIds().SetEquals(other.subject.GetIds());
        }

        #endregion
    }


    public class AllowRule : AccessRule
    {
        public override AccessRuleType type
        {
            get { return AccessRuleType.Allow; }
        }


        public AllowRule(Subject subject, Verb verb, Resource resource) 
            : base(subject, verb, resource)
        {
        }
    }
}
